package myfunc

import (
	"fmt"
	"math/rand"
	"time"
)

func main() {
	result := initDada(10)
	come := getSliceRand(result)
	start(come)

}

func start(come int) {
	fmt.Println("我准备好了，请输入你猜想的数字")
	for {
		var yourInt int
		_, err := fmt.Scan(&yourInt)
		if err != nil {
			return
		}
		ok, tips := getResult(yourInt, come)
		if ok {
			fmt.Println(tips)
			return
		}
		fmt.Println(tips)
	}
}

// initData 初始化数据
func initDada(numRange int) []int {
	var result []int
	for i := 0; i < numRange; i++ {
		result = append(result, i+1)
	}
	return result
}

// getSliceRand 获取随机数
func getSliceRand(slices []int) int {
	rand.New(rand.NewSource(time.Now().UnixNano()))
	randInt := rand.Intn(len(slices))
	return slices[randInt]
}

func getResult(in, come int) (bool, string) {
	if in == come {
		return true, fmt.Sprintln("你猜成功了，我想的也是:", in)
	} else {
		if in > come {
			return false, fmt.Sprintln("你猜成功了结果大了一点，再想想吧")
		} else {
			return false, fmt.Sprintln("你猜成功了结果小了一点，再想想吧")
		}
	}
}
